/*************************************************************************/
/*									 */
/*  Compute the additional errors if the error rate increases to the	 */
/*  upper limit of the confidence level.  The coefficient is the	 */
/*  square of the number of standard deviations corresponding to the	 */
/*  selected confidence level.  (Taken from Documenta Geigy Scientific	 */
/*  Tables (Sixth Edition), p185 (with modifications).)			 */
/*									 */
/****************************Edited by l0he1g****************************/
#ifndef STATS_H
#define STATS_H
#include <cmath>
#pragma warning(disable:4305 4244)

namespace c45{
	float Val[] = {  0,  0.001, 0.005, 0.01, 0.05, 0.10, 0.20, 0.40, 1.00},
        Dev[] = {4.0,  3.09,  2.58,  2.33, 1.65, 1.28, 0.84, 0.25, 0.00};

    float ucf(float N,float e)
    {
		static float Coeff=0;
        const static float CF = config::CF;
        float Pr;

        if ( ! Coeff )
        {
			int i=0;
			while ( CF > Val[i] ) i++;

			Coeff = Dev[i-1] +
				(Dev[i] - Dev[i-1]) * (CF - Val[i-1]) /(Val[i] - Val[i-1]);
			Coeff = Coeff * Coeff;
		}

		if ( e < 1E-6 )
		{
			return exp(log(CF) / N);
		}
		else if( e+0.5>=N )
		{
			return N-e;
		}
		else
		{
			Pr = (e + 0.5 + Coeff/2
                  + sqrt(Coeff * ((e + 0.5) * (1 - (e + 0.5)/N) + Coeff/4)) )
				/ (N + Coeff);
			return Pr;
		}
	}
}
#endif
